<?php

use yii\helpers\Url;
use yii\helpers\Html;
use website\helpers\Render;
use common\models\User;
use common\models\Message;

$this->title = '我的消息';
?>

<div class="contenter">
    <?= $this->render('/user/navigator', ['active' => 'message']) ?>

    <div id="user-contenter">
        <div class="box-shadow pb-20px" id="sub-contenter">
            <div class="data-title"><span class="h3"><?= $this->title ?></span></div>
            <!-- div class="data-title tab">
                <span class="h3 status-"><a href="<//?= Url::to('@web/user/message-list') ?>">所有消息</a></span>
                <span class="h3 status-<//?= Message::StatusUnread ?>"><a href="<//?= Url::to('@web/user/message-list?status='.Message::StatusUnread) ?>"><i class="icon-envelope"></i> 未读</a></span>
                <span class="h3 status-<//?= Message::StatusRead ?>"><a href="<//?= Url::to('@web/user/message-list?status='.Message::StatusRead) ?>"><i class="icon-envelope-alt"></i> 已读</a></span>
            </div -->
            <div class="flyer-table fat simple">
                <table id="info-table" cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="first w-80px"><i class="icon-bell-alt"></i> 类型</th>
                        <th><i class="icon-list-ol"></i> 标题</th>
                        <th class="w-120px"><i class="icon-time"></i> 时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr><td class="first" colspan="3"><i class="icon-search"></i> 点击查询按钮查找数据.</td></tr>
                    </tbody>
                </table>
            </div>
            <div class="flyer-page mt right" id="info-page">
                <div class="html mr-10px"></div>
            </div>
        </div>
    </div>
</div>
<div id="search" style="display:none;">
    <?= Render::select('type', Message::$typeSelector, null) ?>
</div>

<script src="<?= Render::static('art-template/template.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tabler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // $('.status-<//?= $status ?>').addClass('active');
        // 初始化表格异步加载事件
        (new tabler).init({
            // 请求地址
            //url: '<//?= Url::to('@web/user/message-list?status='.$status) ?>',
            url: '<?= Url::to('@web/user/message-list') ?>',
            // 数据渲染配置
            table: '#info-table', page: '#info-page', template: 'info-template', search: '#info-search', readyCall: true,
            // param => tabler
            afterPost: function(param) {
            // 充值方式名称显示
            tableHandler.renderCategory({ category: $(param.tabler).find('.type'), select: '#search select[name=type]' });
        }
        });
    });
</script>
<script id="info-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <tr id="tr-{{info.id}}" data-id="{{info.id}}">
        <td class="first type">{{info.type}}</td>
        <td><a href="<?= Url::to('@web/user/message?id=') ?>{{info.id}}" style="{{if info.status == '<?= Message::StatusUnread ?>'}} font-weight:700;{{/if}}">{{info.title}}</a></td>
        <td>{{info.created_at | dateShow: 'minute'}}</td>
    </tr>
    {{/each}}
    {{else}}
    <tr>
        <td class="first" colspan="3"><i class="icon-ban-circle"></i> 您的站内信空空如也！</td>
    </tr>
    {{/if}}
</script>